{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "74078245",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-01T06:44:55.464794Z",
     "start_time": "2021-11-01T06:44:55.453794Z"
    }
   },
   "outputs": [],
   "source": [
    "info = {\n",
    "    \"stud_1001\":\"Alex\",\n",
    "    \"stud_1002\":\"Mike\",\n",
    "    \"stud_1003\":\"Pina\"\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "5a2cc10c",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-01T06:44:56.440850Z",
     "start_time": "2021-11-01T06:44:56.405848Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'stud_1001': 'Alex', 'stud_1002': 'Mike', 'stud_1003': 'Pina'}"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "d2916af8",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-01T06:47:16.552864Z",
     "start_time": "2021-11-01T06:47:16.533863Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "stud_1001\n",
      "stud_1002\n",
      "stud_1003\n"
     ]
    }
   ],
   "source": [
    "for i in info:\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "024e55d1",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-01T06:49:47.068473Z",
     "start_time": "2021-11-01T06:49:47.052472Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "stud_1001 Alex\n",
      "stud_1002 Mike\n",
      "stud_1003 Pina\n"
     ]
    }
   ],
   "source": [
    "# 循环遍历整个字典\n",
    "for k,v in info.items():\n",
    "    print(k,v)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "50f4aac2",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-01T06:55:20.272531Z",
     "start_time": "2021-11-01T06:55:20.259531Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'1001': 'Alex', '1002': 'Mike', '1003': 'Pina'}"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 实践一：stu_1001 中取出数字，作为新字典key\n",
    "new_info = {}\n",
    "for k,v in info.items():\n",
    "    # 用字典新增的方法创建字典\n",
    "    new_info[k[5:]] = v\n",
    "new_info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "c620c656",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-01T06:58:11.059300Z",
     "start_time": "2021-11-01T06:58:11.046299Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'1001': 'ALEX', '1002': 'MIKE', '1003': 'PINA'}"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 实践2： value 所有字母大写\n",
    "new_info = {}\n",
    "for k,v in info.items():\n",
    "    # 用字典新增的方法创建字典\n",
    "    new_info[k[5:]] = v.upper()\n",
    "new_info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "c5faff36",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-01T07:01:45.401559Z",
     "start_time": "2021-11-01T07:01:45.381558Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{1001: 'Alex', 1002: 'Mike', 1003: 'Pina'}"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 实践3：让new_info key 由 ‘1001’ 变成 1001\n",
    "new_info = {}\n",
    "for k,v in info.items():\n",
    "    # 用字典新增的方法创建字典\n",
    "    new_info[int(k[5:])] = v\n",
    "new_info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8fd83623",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
